package com.ruoyi.web.controller.examine;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.examine.domain.TbGradingRules;
import com.ruoyi.examine.service.ITbGradingRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评分细则Controller
 *
 * @author ruoyi
 * @date 2023-12-28
 */
@RestController
@RequestMapping("/examine/rules")
public class TbGradingRulesController extends BaseController
{
    @Autowired
    private ITbGradingRulesService tbGradingRulesService;

    /**
     * 查询评分细则列表
     */
    @PreAuthorize("@ss.hasPermi('examine:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbGradingRules tbGradingRules)
    {
        startPage();
        List<TbGradingRules> list = tbGradingRulesService.selectTbGradingRulesList(tbGradingRules);
        return getDataTable(list);
    }

    /**
     * 导出评分细则列表
     */
    @PreAuthorize("@ss.hasPermi('examine:rules:export')")
    @Log(title = "评分细则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbGradingRules tbGradingRules)
    {
        List<TbGradingRules> list = tbGradingRulesService.selectTbGradingRulesList(tbGradingRules);
        ExcelUtil<TbGradingRules> util = new ExcelUtil<TbGradingRules>(TbGradingRules.class);
        util.exportExcel(response, list, "评分细则数据");
    }

    /**
     * 获取评分细则详细信息
     */
    @PreAuthorize("@ss.hasPermi('examine:rules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbGradingRulesService.selectTbGradingRulesById(id));
    }

    /**
     * 新增评分细则
     */
    @PreAuthorize("@ss.hasPermi('examine:rules:add')")
    @Log(title = "评分细则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbGradingRules tbGradingRules)
    {
        return toAjax(tbGradingRulesService.insertTbGradingRules(tbGradingRules));
    }

    /**
     * 修改评分细则
     */
    @PreAuthorize("@ss.hasPermi('examine:rules:edit')")
    @Log(title = "评分细则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbGradingRules tbGradingRules)
    {
        return toAjax(tbGradingRulesService.updateTbGradingRules(tbGradingRules));
    }

    /**
     * 删除评分细则
     */
    @PreAuthorize("@ss.hasPermi('examine:rules:remove')")
    @Log(title = "评分细则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbGradingRulesService.deleteTbGradingRulesByIds(ids));
    }
}
